package com.bjsxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjsxt.mapper.CompanyMapper;
import com.bjsxt.pojo.Company;
import com.bjsxt.pojo.PageResult;
import com.bjsxt.service.ICompanyService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-10-14
 */
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements ICompanyService {
    @Override
    public PageResult<Company> selCompanyInfoService(Integer page, Integer rows,String cname,String status,String ordernumber) {
        //创建对象存储分页信息
        System.out.println("????");
        System.out.println(page+":123:"+rows);
        IPage<Company> page1 = new Page<>(page,rows);
        //分页查询
        QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
        if(cname!=null&&!"".equals(cname)){
            queryWrapper.like("cname",cname);
        }
        if(status!=null&&!"".equals(status)){
            queryWrapper.in("status",status);
        }
        if("asc".equals(ordernumber)){
            queryWrapper.orderByAsc("ordernumber");
        }else if("desc".equals(ordernumber)){
            queryWrapper.orderByDesc("ordernumber");
        }
        IPage<Company> companyIPage = baseMapper.selectPage(page1, queryWrapper);
        //将结果封装到PageResult
        PageResult<Company> pageResult = new PageResult<>();
        pageResult.setRows(companyIPage.getRecords());
        pageResult.setTotal(companyIPage.getTotal());

        return pageResult;
    }
}
